﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 移动支付
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://localhost:3501/Default.aspx");
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlDocument doc = webBrowser1.Document; //获取document对象
            HtmlElement btn = null;
            foreach (HtmlElement em in doc.All) //轮循
            {
                string str = em.Name;

                if (em.Name == "MBLNO_OR_LOGID") //减少处理
                {
                    em.SetAttribute("value", "18746457565");
                }
                else if (em.Name == "LOG_PSWD")
                {
                    em.SetAttribute("value", "wzhls777");
                }
                if (em.Id == "LOG_PSWDssc")
                {
                    em.InvokeMember("click");
                    break;
                }
            }/*
            if (webBrowser1.Url.ToString() == "https://cmpay.10086.cn/")
            {
                HtmlDocument doc = webBrowser1.Document; //获取document对象
                HtmlElement btn = null;
                foreach (HtmlElement em in doc.All) //轮循
                {
                    string str = em.Name;

                    if (em.Name == "MBLNO_OR_LOGID") //减少处理
                    {
                        em.SetAttribute("value", "18746457565");
                    }
                    else if (em.Name == "LOG_PSWD")
                    {
                        em.SetAttribute("value", "wzhls777");
                    }
                    if (em.Id == "login")
                    {
                        em.InvokeMember("click");
                        break;
                    }
                }
                //webBrowser1.Navigate("https://cmpay.10086.cn/service/register.xhtml?WT.ad_id=indexLoginzhuce");
            }
            else if (webBrowser1.Url.ToString() == "https://cmpay.10086.cn/service/register.xhtml?WT.ad_id=indexLoginzhuce")
            {
                //MessageBox.Show("123");
                HtmlDocument doc = webBrowser1.Document; //获取document对象
                HtmlElement btn = null;
                foreach (HtmlElement em in doc.All) //轮循
                {
                    string str = em.Name;

                    if (em.Name == "REG_MBL_NO") //减少处理
                    {
                        em.SetAttribute("value", "18746128628"); 
                    }
                    if(em.Id=="fsyzm")
                    {
                        em.InvokeMember("click");
                        break;
                    }
                }
            }
            else if (webBrowser1.Url.ToString() == "https://cmpay.10086.cn/service/register.xhtml?WT.ad_id=indexLoginzhuce#")
            {
                
            }
            else if (webBrowser1.Url.ToString().IndexOf("https://cmpay.10086.cn/service/register_first.xhtml?token=") != -1)
            {
                MessageBox.Show("ok");
            }
            else
            {
                MessageBox.Show("未知网页");
            }


            */
            //btn.InvokeMember("click"); //触发submit事件
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            HtmlDocument doc = webBrowser1.Document; //获取document对象
            HtmlElement btn = null;
            foreach (HtmlElement em in doc.All) //轮循
            {
                string str = em.Name;
                if (em.Id == "LOG_PSWDssc")
                {
                    btn = em;
                    break;
                }
                if (em.Name == "CHK_NO") //减少处理
                {
                    em.SetAttribute("value", toolStripTextBox1.Text);
                }
                if (em.Id == "submit1")
                {
                    em.InvokeMember("click");
                    break;
                }
            }
        }
    }
}
